//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.IO;
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet.Formats.Biff.Tokens
{
    internal class AreaErrorToken : FormulaToken
    {
        private readonly AccessorType _type;

        public AreaErrorToken(AccessorType type)
        {
            _type = type;
        }

        public override ushort GetLength(FormulaReadContextType formulaReadContextType)
        {
            return 8;
        }
        public override FormulaTokenId TokenId
        {
            get { 
                switch (_type)
                {
                    case AccessorType.Array:
                        return FormulaTokenId.AreaErrA;
                        case AccessorType.Reference:
                        return FormulaTokenId.AreaErr;
                        case AccessorType.Value:
                        return FormulaTokenId.AreaErrV;
                    default: throw new NotSupportedException();
                }
            }
        }

        internal override void ReadContent(FormulaReadContext context)
        {
            context.ReadBytes(GetLength(context.Type));
        }

        internal override Expression GetExpression(FormulaEvaluationContext context)
        {
            return new ErrorExpression(Errors.RefError);
        }

        public override void WriteContent(FormulaWriteContext context)
        {
            throw new NotImplementedException();
        }
    }
}